import CryptoJS from 'crypto-js';
// 封装一个localstorage，并且安装一个crypto-js插件，加密一下localstorage里的数据
const getUserData = () => {
    let result = localStorage.getItem('zhouqing');
    if (result) {
        result = CryptoJS.AES.decrypt(result.toString(), 'miyao').toString(CryptoJS.enc.Utf8);
    }
    return result;
};

const setUserData = (account) => {
    // encrypt()方法的第一个参数是要加密的数据，第二个参数是加密第一个参数值用的密钥
    const encryptResult = CryptoJS.AES.encrypt(account, 'miyao');
    localStorage.setItem('zhouqing', encryptResult);
};

const removeUserData = () => {
    localStorage.removeItem('zhouqing');
};

export default {
    getUserData,
    setUserData,
    removeUserData,
};